package com.ruoyi.web.controller.house;

import com.ruoyi.house.domain.WebmagicAgencyData;
import com.ruoyi.house.service.IWebmagicAgencyDataService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 房产签约Controller
 * 
 * @author ruoyi
 * @date 2023-06-09
 */
@Controller
@RequestMapping("/house/data")
public class WebmagicAgencyDataController extends BaseController
{
    private String prefix = "house/data";

    @Autowired
    private IWebmagicAgencyDataService webmagicAgencyDataService;

    @RequiresPermissions("house:data:view")
    @GetMapping()
    public String data()
    {
        return prefix + "/data";
    }

    /**
     * 查询房产签约列表
     */
    @RequiresPermissions("house:data:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WebmagicAgencyData webmagicAgencyData)
    {
        startPage();
        List<WebmagicAgencyData> list = webmagicAgencyDataService.selectWebmagicAgencyDataList(webmagicAgencyData);
        return getDataTable(list);
    }

    /**
     * 导出房产签约列表
     */
    @RequiresPermissions("house:data:export")
    @Log(title = "房产签约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WebmagicAgencyData webmagicAgencyData)
    {
        List<WebmagicAgencyData> list = webmagicAgencyDataService.selectWebmagicAgencyDataList(webmagicAgencyData);
        ExcelUtil<WebmagicAgencyData> util = new ExcelUtil<WebmagicAgencyData>(WebmagicAgencyData.class);
        return util.exportExcel(list, "房产签约数据");
    }

    /**
     * 新增房产签约
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存房产签约
     */
    @RequiresPermissions("house:data:add")
    @Log(title = "房产签约", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WebmagicAgencyData webmagicAgencyData)
    {
        return toAjax(webmagicAgencyDataService.insertWebmagicAgencyData(webmagicAgencyData));
    }

    /**
     * 修改房产签约
     */
    @RequiresPermissions("house:data:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WebmagicAgencyData webmagicAgencyData = webmagicAgencyDataService.selectWebmagicAgencyDataById(id);
        mmap.put("webmagicAgencyData", webmagicAgencyData);
        return prefix + "/edit";
    }

    /**
     * 修改保存房产签约
     */
    @RequiresPermissions("house:data:edit")
    @Log(title = "房产签约", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WebmagicAgencyData webmagicAgencyData)
    {
        return toAjax(webmagicAgencyDataService.updateWebmagicAgencyData(webmagicAgencyData));
    }

    /**
     * 删除房产签约
     */
    @RequiresPermissions("house:data:remove")
    @Log(title = "房产签约", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(webmagicAgencyDataService.deleteWebmagicAgencyDataByIds(ids));
    }
}
